/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tree;

/**
 *
 * @author adam
 */
public class AllocTree extends VyrazTree {
    private VyrazTree lt;
    private int dimension;

    public AllocTree(Position p1, Position p2, VyrazTree lt,int dimension){
        super(p1,p2);
        this.lt = lt;
        this.dimension=dimension;    
        
    }

    @Override
    public Type getType() {
        return Type.POINTER;   
    }
    
    @Override
    public String toString() {
        return String.format("Alloc %s: [%s,%s]", super.toString(), getVyrazTree(), getDimension());
    }
    
    @Override
    public void accept(TreeVisitor visitor) {
        visitor.visitAlloc(this);
    }



    @Override
    public void generate(Context ctx) {
        this.getVyrazTree().generate(ctx);
        
            //String zavorky="[";
            //for(int i=1;i<dimension;i++){
              //  zavorky=zavorky+"[";
            //}
            ctx.println("newarray "
                    //+zavorky+"I "
                    +getDimension());
        
            
        
    }

    /**
     * @return the dimension
     */
    public int getDimension() {
        return dimension;
    }

    /**
     * @param dimension the dimension to set
     */
    public void setDimension(int dimension) {
        this.dimension = dimension;
    }

    /**
     * @return the lt
     */
    public VyrazTree getVyrazTree() {
        return lt;
    }
}